package com.richard.library.basic.util;

import android.os.Build;
import android.view.View;
import android.view.Window;

/**
 * author Richard
 * date 2020/12/18 18:01
 * version V1.0
 * description: 隐藏系统底部导航栏工具类
 */
public class HideNavBarUtil {

    public static void hideBottomUIMenu(Window window){
        HideNavBarUtil.hideBottomUIMenu(window.getDecorView());
    }

    /**
     * 隐藏底部导航栏
     */
    public static void hideBottomUIMenu(View v) {
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN;
            v.setSystemUiVisibility(uiOptions);
        }
    }

    /**
     * 调起输入法 用于隐藏输入法后隐藏导航栏
     */
    public static void hideWhenSystemUiVisible(View v) {
        v.setOnSystemUiVisibilityChangeListener(visibility -> {
            if (visibility == View.SYSTEM_UI_FLAG_VISIBLE) {
                hideBottomUIMenu(v);
            }
        });
    }
}
